<template>
  <div class="app-container">
    <nabtwo index="3" :params="param"></nabtwo>
    <!-- 搜索栏部分 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" class="frominfo">
      <el-form-item label="标题" prop="assistTitle" style="width: 80%;">
        <el-input v-model="queryParams.assistTitle" @keyup.enter.native="handleQuery" placeholder="请输入角色标题" clearable />
      </el-form-item>
      <div class="from-Btn">
          <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
      </div>
    </el-form>
    <!-- 新增按钮操作 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增角色</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 信息部分框 -->
    <el-row :gutter="20" class="card">
      <el-col :span="8" v-for="(item, index) in wcAssistGreetInfoList" :key="index">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span><i class="el-icon-user"></i>{{ item.assistTitle }}</span>
            <div class="ass">{{ item.assistJob }}</div>
          </div>
          <div>
            <!-- <el-checkbox v-model="item.checked" @change="handleSelectionChange(item)"></el-checkbox> -->
            <div class="text item">
              <!-- 这里可以添加操作按钮，例如编辑和删除 -->
              <el-button style="float: right; padding: 0px 10px; margin-right: 10px;margin-top: -5px;" type="text"
                icon="el-icon-delete" @click="handleDelete(item)"></el-button>
              <el-button style="float: right; padding: 0px;margin-top: -5px;" type="text" icon="el-icon-edit"
                @click="handleUpdate(item)"></el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-empty v-if="wcAssistGreetInfoList==''||wcAssistGreetInfoList==null" description="暂无数据"></el-empty>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改助手信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="assistTitle">
          <el-input v-model="form.assistTitle" placeholder="请输入标题" />
        </el-form-item>

        <el-form-item label="提示词" prop="assistJob">
          <el-input v-model="form.assistJob" type="textarea" rows="6" placeholder="请输入提示词" />
        </el-form-item>
        <el-form-item label="是否使用" prop="selectFlag">
          <el-checkbox v-model="form.selectFlag"></el-checkbox>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>

import request from '@/utils/request'
import nabtwo from '../../components/nabtwo.vue'
export default {
  name: "WcAssistGreetInfo",
  components: {
    nabtwo
  },
  data() {
    return {
      param: { wxid:this.$route.query.wxid,userid:this.$route.query.userid},//这是点击切换到另个组件是传递的数，
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      wcAssistGreetInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        assistId: this.$route.query.userid, 
        assistTitle: null,
        assistJob: null,
        assistJob: null,
        assistAge: null,
        assistNature: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询助手招呼语设置列表 */
    getList() {
      this.loading = true;
      listWcAssistGreetInfo(this.queryParams).then(res => {
        if (res['success']) {
          const dt = res['data'];
          this.total = dt['total'];
          this.wcAssistGreetInfoList = dt['records'];
        }
        this.loading = false;
      });
      setTimeout(()=>{
        this.loading = false;
      },2000)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        assistId: this.$route.query.userid,
        assistTitle: null,
        assistJob: null,
        assistJob: null,
        assistAge: null,
        assistNature: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        selectFlag:0,
        assistContent: null,
        // 开启Ai:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      // 重置表单
      this.resetForm("queryForm");
      this.queryParams.assistId=this.$route.query.userid
      // 重新获取数据列表
      this.getList();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加角色设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getWcAssistGreetInfo(id).then(response => {
        response.data.selectFlag=response.data.selectFlag==1?true:false
        this.form = response.data;
        this.open = true;
        this.title = "修改角色设置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      //console.log(this.form)
      if(this.form.selectFlag){
        this.form.selectFlag=1
      }else{
        this.form.selectFlag=0
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWcAssistGreetInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWcAssistGreetInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除助手招呼语的数据项？').then(function () {
        return delWcAssistGreetInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('arbit/wcassist_greet_info/export', {
        ...this.queryParams
      }, `wcAssistGreetInfo_${new Date().getTime()}.xlsx`)
    }
  }
};

/** js请求 调用 */

// 查询助手招呼语设置列表
export function listWcAssistGreetInfo(query) {
  return request({
    url: '/wxassistant/wcassist_greet_info/page',
    method: 'get',
    params: query
  })
}

// 查询助手招呼语设置详细
export function getWcAssistGreetInfo(id) {
  return request({
    url: '/wxassistant/wcassist_greet_info/queryById/' + id,
    method: 'get'
  })
}

// 新增助手招呼语设置
export function addWcAssistGreetInfo(data) {
  return request({
    url: '/wxassistant/wcassist_greet_info/add',
    method: 'post',
    data: data
  })
}

// 修改助手招呼语设置
export function updateWcAssistGreetInfo(data) {
  return request({
    url: '/wxassistant/wcassist_greet_info/edit',
    method: 'put',
    data: data
  })
}

// 删除助手招呼语设置
export function delWcAssistGreetInfo(id) {
  return request({
    url: '/wxassistant/wcassist_greet_info/delete/' + id,
    method: 'delete'
  })
}

</script>
<style lang="scss" scoped>
.box-card {
  margin-bottom: 20px;
}
.frominfo{
      display: flex;background-color: #fff;padding: 10px;padding-bottom: 0; margin-bottom: 20px;
      .from-item{
        display: flex;flex-wrap: wrap;
      }
      .from-Btn{
        display: flex;flex-direction: column;align-items: center;justify-content: center;width: 20%;
      }
}
.clearfix {
  height: 105px;

  span {
    font-weight: bold;

    i {
      color: rgb(12, 112, 228);
      margin-right: 20px;
    }
  }

  .ass {
    font-size: 12px;
    color: rgb(184, 181, 178);
    margin-top: 20px;
    display: -webkit-box; // 将对象作为弹性伸缩盒子模型显示
    -webkit-box-orient: vertical; // 设置或检索伸缩盒对象的子元素的排列方式
    -webkit-line-clamp: 4; // 显示两行
    overflow: hidden;
  }
}


.app-container {
  background-color: #f6f9fb;
}

.el-col-8 {
  width: 320px;
}

</style>